package com.op.teachingliteapp.fragment.resource;

import java.util.ArrayList;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;

import com.op.teachingliteapp.R;
import com.op.teachingliteapp.activity.CourseActivity;
import com.op.teachingliteapp.fragment.resourcedetails.ResourceDetailsFragment;

public class ResouceFragment extends Fragment {

	private GridView gridview_material;
	ArrayList<ResourceCellDataProvider>  list_material=new ArrayList<ResourceCellDataProvider>();
	   private ResourceGridAdapter mAdapter;
	   private int index=0;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View root = inflater.inflate(R.layout.fragment_resource, container,false);
		gridview_material=(GridView)root.findViewById(R.id.gridView_material);
		mAdapter=new ResourceGridAdapter(getActivity(), list_material);
		gridview_material.setAdapter(mAdapter);
		
		//课程PPT
//		root.findViewById(R.id.class_ppt).setOnClickListener(new OnClickListener() {
//			
//			@Override
//			public void onClick(View v) {
//				getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.main_show2, new ppt_listview_choice()).commit();
//				Toast.makeText(getActivity(), "课程PPT", Toast.LENGTH_SHORT).show();
//				MainActivityTwo.setBackChoice(2);
//			}
//		});
		
		gridview_material.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				if(position==list_material.size()-1){
					switch(index){
					case 0:
						mAdapter.add(new ResourceCellDataProvider("课程PPT",R.drawable.ppt1));index++;break;
					case 1:
						mAdapter.add(new ResourceCellDataProvider("上机实验",R.drawable.sjsy1));index++;break;
					case 2:
						mAdapter.add(new ResourceCellDataProvider("视频资料",R.drawable.spzl1));index++;break;
					case 3:
						mAdapter.add(new ResourceCellDataProvider("课程案例",R.drawable.kcal1));index++;break;
					case 4:
						mAdapter.add(new ResourceCellDataProvider("上课计划",R.drawable.kcjh1));index++;break;
					case 5:
						mAdapter.add(new ResourceCellDataProvider("学生名单",R.drawable.xsmd1));index=0;break;
					}
				}
				if(position==0){
					/*
					 * 从这里点击进入ppt的选择
					 */
					CourseActivity.setBackChoice(2);
					getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.main_show2, new ResourceDetailsFragment()).commit();
				}else{
					Toast.makeText(getActivity(),"可点击"+position, Toast.LENGTH_SHORT).show();
				}
			}
		});
		
		
		
		return root;
	}
	
}
